import re


def format_requests_num(req: int) -> str:
    """格式化请求数为带单位的字符串（例如：50000000 -> 50M），只建议使用在整1e12以内的整K/M/G整数上"""
    unit = ['', 'K', 'M', 'G']
    idx = 0
    if req >= 1e12:
        return str(req)
    while req >= 1000:
        req = req // 1000
        idx += 1
    return f'{req}{unit[idx]}'


def check_resource_num(num: str) -> bool:
    pattern = re.compile(r'^([0-9]+m|[0-9]+(\.[0-9]+)?)$')
    return re.fullmatch(pattern, num) is not None